package com.aeon.asm;

import java.util.List;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
 public class MyClassAdapter extends ClassNode implements Opcodes { 
    private ClassVisitor cv; 
    public MyClassAdapter(ClassVisitor cv) { 
      this.cv = cv; 
    } 

    @Override
    public void visitEnd() { 
      for (MethodNode mn : (List<MethodNode>) methods) {
//        if (mn.name.equals("go")) {

          InsnList il = new InsnList();
          il.add(new FieldInsnNode(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"));
          il.add(new LdcInsnNode("I live!"));
          il.add(new MethodInsnNode(INVOKEVIRTUAL, "java/io/PrintStream", 
            "println", "(Ljava/lang/String;)V"));
          mn.instructions.insert(il);

          mn.maxStack +=2;
//        }
      }      accept(cv); 
    } 
  }
